"""
Case Type   : 共享存储-系统内部工具-dsscmd
Case Name   : dsscmd工具进行加密
Create At   : 2023/4/12
Owner       : opentestcase019
Description :
    1.dsscmd工具进行加密
Expect      :
    1.加密成功
History     :
"""
import os
import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common


class ShareStorageTool(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f"-----{os.path.basename(__file__)} start-----")
        self.primary_node = Node('PrimaryDbUser')
        self.common = Common()

    def test_sharestorage_tool(self):
        step1 = "-----step1:dsscmd工具进行加密;expect:加密成功-----"
        self.logger.info(step1)
        execute_cmd = f'''source {macro.DB_ENV_PATH};
                          expect <<EOF
                          set timeout 120
                          spawn dsscmd encrypt
                          expect "Please enter password to encrypt:"
                          send "{macro.COMMON_PASSWD}\\n"
                          expect "Please input password again:"
                          send "{macro.COMMON_PASSWD}\\n"
                          expect eof\n''' + '''EOF'''
        self.logger.info(execute_cmd)
        execute_msg = self.common.get_sh_result(self.primary_node, execute_cmd)
        self.assertIn("Cipher:", execute_msg, "执行失败" + step1)
        self.assertNotIn("error", execute_msg, "执行失败" + step1)

    def tearDown(self):
        self.logger.info("-----无需环境清理-----")
        self.logger.info(f"-----{os.path.basename(__file__)} end-----")
